// JavaScript Document
$(function(){
    var screenheight = $(window).height();
    //alert(screenheight);
    $(".Head .Hnav .HeadUnderline").width($(".Head .Hnav .HnavUl li").eq(0).width())
    $(".Head .Hnav .HnavUl li").hover(function () {
        $(".Head .Hnav .HeadUnderline").stop().animate({
            left:$(this).offset().left,
            width:$(this).width(),
        },500)
    }, function () {
        $(".Head .Hnav .HeadUnderline").stop().animate({
            left:$(".Head .Hnav .HnavUl li").eq(0).offset().left,
            width:$(".Head .Hnav .HnavUl li").eq(0).width(),
        },500)
    })

    /*banner*/
    var num=0;
    function show(){
        if(num>2){
            num=0;
            $('.banner img').eq(num).addClass('current').siblings().removeClass('current');
            $('.HlittleBtn ul li').eq(num).addClass('current').siblings().removeClass('current');
        }else{
            num++;
            $('.banner img').eq(num).addClass('current').siblings().removeClass('current');
            $('.HlittleBtn ul li').eq(num).addClass('current').siblings().removeClass('current');
        }
    }

    var timer = setInterval(function(){
        show();
    },8000);

    $('.HlittleBtn ul li').click(function(e) {
        num=$(this).index();
        $('.banner img').eq($(this).index()).addClass('current').siblings().removeClass('current');
        $(this).addClass('current').siblings().removeClass('current');
    });


    /*top*/
    $('.top').click(function(e) {
        $('body,html').animate({'scrollTop':'0'},500);
    });

    /*lProject01*/
    $('.lProject01').hover(function(e) {
        $(this).children('p').css('color','#fff');
        $(this).find('.sever').css({'background': 'url(/public/img/bn/specialIcon.png) 0 0'});
        $(this).find('.fly').css({'background':'url(/public/img/bn/specialIcon.png) 0 -31px'});
        $(this).find('.car').css({'background':'url(/public/img/bn/specialIcon.png) 0 -59px'});
    },function(){
        $(this).children('p').css('color','#000');
        $(this).find('.sever').css({'background':'url(/public/img/bn/specialIcon01.png) 0 0'});
        $(this).find('.fly').css({'background':'url(/public/img/bn/specialIcon01.png) 0 -31px'});
        $(this).find('.car').css({'background':'url(/public/img/bn/specialIcon01.png) 0 -59px'});
    });



    /*north*/
    function mapChangeColor(x,y){
        $('.'+x+'').hover(function(e) {
            $(this).find('img').attr('src','/public/img/bn/'+y+'01.png');
        },function(){
            $(this).find('img').attr('src','/public/img/bn/'+y+'.png');
        });
    }
    mapChangeColor('north','southamercia');
    mapChangeColor('south','northAmercia');
    mapChangeColor('europ','europ');
    mapChangeColor('Africa','Africa');
    mapChangeColor('asia','asia');


    $('.north img').click(function(e) {
        $('.little3jiao').css('left','22%');
    });
    $('.south img').click(function(e) {
        $('.little3jiao').css('left','32%');
    });
    $('.europ img').click(function(e) {
        $('.little3jiao').css('left','43%');
    });
    $('.Africa img').click(function(e) {
        $('.little3jiao').css('left','53%');
    });
    $('.asia img').click(function(e) {
        $('.little3jiao').css('left','64%');
    });


    /*commonNav*/

    $('.cnInUl ul li').click(function(e) {
        $(this).addClass('current').siblings().removeClass('current');
    });

    $(window).scroll(function(e) {
        if($(window).scrollTop()>150){
            $('.cnIn').css({'position':'fixed','top':'0','background':'rgba(0,0,0,0.6)'});
        }else{
            $('.cnIn').css({'position':'aboslute','top':'100px','background':'rgba(0,0,0,0.2)'});
        }
    });

    //MCenterIn中Map的点击事件，点中北美就将北美放在后面的框中
    $('.MCenterIn .Map').click(function(e) {

        var dress = $(this).find('.chinaName').html();
        //alert($('.checked').val());
        var newOption = "<option selected>"+dress+"</option>";
        $('.sbCenter .select01 option').remove();
        $('.sbCenter .select01').append(newOption);

    });
    //精选度假屋鼠标滑动效果
    $('.hoverDetail').hide();
    $('.projectall').hover(function(){
        $(this).find('.projectallCenterBg').hide();
        $(this).find('.hoverDetail').show();
    },function(){
        $(this).find('.hoverDetail').hide();
        $(this).find('.projectallCenterBg').show();
    })

    //导航滚动栏
    var def="",$this;
    $(".selected input[type=text]").click(function(){
        $(this).next().next(".choose").show()
        $(this).parents(".selected").siblings().find(".choose").hide()
        $("#shade").show();
        if($this){
            $this.val(def)
        }
        $this=$(this);
        def=$(this).val();
        $(this).val("")
    })
    $(".selected .choose a").on('click',function(){
        def=$(this).text();
        $this.val(def);
        $this.next("input[type=hidden]").val($(this).attr("valuea"));

        $(".selected .choose").hide();
        $("#shade").hide();
    })
    $("#shade").on('click',function(){
        $(".selected .choose").hide();
        $this.val(def);
        $(this).hide()
    })
});

/*导航滑动*/

$(window).scroll(function(e) {
    if($(window).scrollTop()>$(window).height()) {
        $('.bieshuBannerIn').addClass('navScroll');
    }else{
        $('.bieshuBannerIn').removeClass('navScroll');
    }
});
$("img.lazy").lazyload();

$(function () {
    $.ajax({
        url: "/front/user_info/userinfo",
        success: function (data) {
            var userName = data.username;
            var imageGuid = data.imageGuid;
            if (userName != null) {
                if($(window).width()==768){
                    $(".aboutBtn").hide();
                    $(".loginBtn").show();
                    $(".noLogin").hide();
                }else{
                $(".noLogin").hide();
                $(".logined").show();
                $("#userName").html(userName);
                $("#userAlert img").attr({src: "/public/image/" + imageGuid});
                $("#userAlert .alertUserName").html(userName);
                $(".HnavSign").hover(function () {
                    $("#userAlert").show()
                }, function () {
                    $("#userAlert").hide()
                })
                }
            }
        }
    });
});

function dispatcher(param) {
    var url = "/";
    if (param == "HOUSE") {
        url = "/front/houseBase/list/HOUSEBASE";
    } else if (param == "APARTMENT") {
        url = "/front/houseBase/list/APARTMENT";
    } else if (param == "PROFILE") {
        url = "/front/user_info/form";
    } else if (param == "ABOUT") {
        url = "/front/about/show/introduce";
    }
    location.href = url;
}

function search() {
    var destination = $(".destination  input[type=hidden]").val();
    var theme = $(".theme input[type=hidden]").val();
    var price = $(".price input[type=hidden]").val();
    var type = $(".type input[type=hidden]").val();
    location.href = "/front/houseBase/list/"+destination+"/"+price+"/"+theme+"/"+type;
}
if($(window).width()>768){
    var divHeight = $(window).height();
}else{
    var divHeight = $(window).height()/2;
}
$('.Head').css('height', divHeight);

